{% extends main.html %}
{% block content %}

  {% set ts = tasks[Task] %}
  <h1 class="title"> Task: {{ ts.key }} </h1>

      <table class="table">
          <tr>
              <th> Status </th>
              <td> {{ ts.state }} </td>
          </tr>
          {% if ts.processing_on %}
          <tr>
              <th> Processing on </th>
              <td><a href="../worker/{{ url_escape(ts.processing_on.address) }}.html">{{ts.processing_on.address}}</a></td>
          </tr>
          <tr>
              <th> Call stack </th>
              <td><a class="button is-primary" href="../call-stack/{{ url_escape(Task) }}.html">Call Stack</a></td>
          </tr>
          {% end %}
          {% if ts.type %}
          <tr>
              <th> Type </th>
              <td> {{ ts.type }} </td>
          </tr>
          {% end %}
          {% if ts.nbytes %}
          <tr>
              <th> Bytes </th>
              <td> {{ format_bytes(ts.nbytes) }} </td>
          </tr>
          {% end %}
          {% if ts.state == 'waiting' %}
          {% for dts in ts.waiting_on %}
          <tr>
              <td> waiting on </td>
              <td><a href="{{ url_escape(dts.key) }}.html">{{dts.key}}</a> </td>
          </tr>
          {% end %}
          {% end %}
          <tr>
              <th> Priority </th>
              <td>{{ts.priority}}</td>
          </tr>
          {% for attr in ['has_lost_dependencies', 'host_restrictions', 'worker_restrictions', 'resource_restrictions', 'loose_restrictions', 'suspicious', 'retries', 'metadata'] %}
          {% if getattr(ts, attr) %}
          <tr>
              <th> {{attr.replace('_', ' ').title()}} </th>
              <td> {{getattr(ts, attr)}} </td>
          </tr>
          {% end %}
          {% end %}
      </table>

    <div id="dependencies-dependents" class="columns">
      <div id="dependencies" class="column">
        <h3 class="title is-5"> Dependencies </h3>
        <table class="table is-striped is-hoverable">
          <thead>
            <th> Key </th>
            <th> State </th>
          </thead>
          {% for dts in ts.dependencies %}
          <tr>
            <td> <a href="{{ url_escape(dts.key) }}.html">{{dts.key}}</a> </td>
            <td> {{ dts.state }} </td>
          </tr>
          {% end %}
        </table>
      </div><!-- #dependencies -->

      <div id="dependents" class="column">
        <h3 class="title is-5"> Dependents </h3>
        <table class="table is-striped is-hoverable">
          <thead>
            <th> Key </th>
            <th> State </th>
          </thead>
          {% for dts in ts.dependents %}
          <tr>
            <td> <a href="{{ url_escape(dts.key) }}.html">{{dts.key}}</a> </td>
            <td> {{ dts.state }} </td>
          </tr>
          {% end %}
        </table>
      </div><!-- #dependents -->
    </div><!-- #dependencies-dependents -->

    <div id="workers-clients" class="columns">
      {% if ts.state == 'memory' %}
      <div id="workers" class="column">
        <h3 class="title is-5"> Workers with data </h3>
          {% set worker_list = ts.who_has %}
          {% include "worker-table.html" %}
      </div><!-- #workers -->
      {% end %}

      {% if ts.who_wants %}
      <div id="clients" class="column">
        <h3 class="title is-5"> Clients with future </h3>
        <div class="content">
          <ul>
            {% for cs in ts.who_wants %}
            <li> <a href="../client/{{ url_escape(cs.client_key) }}.html">{{cs.client_key}}</a></li>
            {% end %}
          </ul>
        </div>
      </div><!-- #clients -->
      {% end %}
    </div><!-- #workers-clients -->

      <div id="transition-log" class="section">
        <h3 class="title is-5"> Transition Log </h3>
          <table class="table is-bordered is-striped is-hoverable">
              <thead>
                  <th> Time </th>
                  <th> Key </th>
                  <th> Start </th>
                  <th> Finish </th>
                  <th> Recommended Key </th>
                  <th> Recommended Action </th>
              </thead>

              {% for key, start, finish, recommendations, transition_time in scheduler.story(Task) %}
              <tr>
                  <td> {{ fromtimestamp(transition_time) }} </td>
                  <td> <a href="{{ url_escape(key) }}.html">{{key}}</a> </td>
                  <td> {{ start }} </td>
                  <td> {{ finish }} </td>
                  <td> </td>
                  <td> </td>
              </tr>
                {% for key2, rec in recommendations.items() %}
              <tr>
                  <td> </td>
                  <td> </td>
                  <td> </td>
                  <td> </td>
                  <td> <a href="{{ url_escape(key2) }}.html">{{key2}}</a> </td>
                  <td> {{ rec }} </td>
              </tr>
                {% end %}
              {% end %}
          </table>
      </div><!-- #transition-log -->
{% end %}
